<template>
  <div class="usersmanage-container">
    <breadcrumb style="position: absolute;width:100%;"></breadcrumb>
    <div class="content">
      <div class="query">
        <div class="margin_right_20">
          团长ID:&nbsp;
          <el-input
            v-model="value1"
            placeholder="请输入内容"
            style="width:100px;height:30px;"
            @keyup.enter.native="get_teamList(1)"
          ></el-input>
        </div>
        <div class="margin_right_20">
          状态:&nbsp;
          <el-select v-model="value2" style="width: 100px;">
            <el-option
              v-for="item in options2"
              :key="item.value2"
              :label="item.label"
              :value="item.value2"
            ></el-option>
          </el-select>
        </div>
        <div class="btn">
          <el-button type="primary" icon="el-icon-search" @click="get_teamList(1)">查询</el-button>
        </div>
      </div>
      <div class="table">
        <el-table :data="teamList" style="width: 100%" height="598">
          <el-table-column prop="usrNo" label="团长ID"></el-table-column>
          <el-table-column prop="userName" label="团长昵称"></el-table-column>
          <el-table-column label="直推团队">
            <el-table-column label="总人数(人)">
              <template slot-scope="scope">
                <el-button
                  type="text"
                  size="small"
                  @click="jump_users_detail1(scope.row.userId)"
                >{{scope.row.oneTeamNum}}</el-button>
              </template>
            </el-table-column>
            <el-table-column label="总消费(元)">
              <template slot-scope="scope">
                <el-button
                  type="text"
                  size="small"
                  @click="jump_users_detail2(scope.row.userId)"
                >{{scope.row.oneTeamConsumeSum}}</el-button>
              </template>
            </el-table-column>
            <el-table-column label="今日入团人数(人)">
              <template slot-scope="scope">
                <el-button
                  type="text"
                  size="small"
                  @click="jump_users_detail3(scope.row.userId)"
                >{{scope.row.intoOneTemNum}}</el-button>
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column label="间推团队">
            <el-table-column label="总人数(人)">
              <template slot-scope="scope">
                <el-button
                  type="text"
                  size="small"
                  @click="jump_users_detail4(scope.row.userId)"
                >{{scope.row.twoTeamNum}}</el-button>
              </template>
            </el-table-column>
            <el-table-column label="总消费(元)">
              <template slot-scope="scope">
                <el-button
                  type="text"
                  size="small"
                  @click="jump_users_detail5(scope.row.userId)"
                >{{scope.row.twoTeamConsumeSum}}</el-button>
              </template>
            </el-table-column>
            <el-table-column prop="username" label="今日入团人数(人)">
              <template slot-scope="scope">
                <el-button
                  type="text"
                  size="small"
                  @click="jump_users_detail6(scope.row.userId)"
                >{{scope.row.intoTwoTeamNum}}</el-button>
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column label="账户操作" width="150">
            <template slot-scope="scope">
              <div>
                <span>{{scope.row.auditStatus=='1'?'正常':'冻结'}}</span>
              </div>
              <div id="box">
                <el-button
                  type="text"
                  size="small"
                  @click="handleForbidden(scope.row.auditStatus,scope.row.userId)"
                >{{scope.row.auditStatus=='1'?'冻结':'正常'}}</el-button>
              </div>
            </template>
          </el-table-column>
        </el-table>
        <pagination
          :currentPage="currentPage"
          :page="page"
          :total="total"
          :pageSize="pageSize"
          @change-current="currentChange"
          @change-size="sizeChange"
        ></pagination>
      </div>
    </div>
  </div>
</template>

<script>
import breadcrumb from "../../components/breadcrumb";
import pagination from "../../components/page";

export default {
  components: { breadcrumb, pagination },
  data() {
    return {
      currentPage: 1,
      pageSize: 10,
      teamList: [],
      total: 0,
      intoOneTemNum: "",
      intoTwoTeamNum: "",
      oneTeamConsumeSum: "",
      oneTeamNum: "",
      twoTeamConsumeSum: "",
      twoTeamNum: "",
      options2: [
        {
          value2: "",
          label: "全部"
        },
        {
          value2: "1",
          label: "正常"
        },
        {
          value2: "0",
          label: "冻结"
        }
      ],

      value: "",
      value1: "",
      value2: "",
      value3: "",
      page: 1
    };
  },
  created() {
   
    if (localStorage.getItem("pageMsg")) {
      let pageMsg = JSON.parse(localStorage.getItem("pageMsg"));
      this.value1 = pageMsg.value1;
      this.value2 = pageMsg.value2;
      this.currentPage = pageMsg.currentPage;
      this.pageSize = pageMsg.pageSize;
      localStorage.removeItem("pageMsg");
    }
    this.get_teamList();
  },
  methods: {
    sizeChange(val) {
      this.pageSize = val;
      this.currentPage = 1;
      this.get_teamList();
    },
    currentChange(val) {
      this.currentPage = val;
      this.get_teamList();
    },
    get_teamList(currentPage) {
      if (currentPage) {
        this.currentPage = currentPage;
      }
      this.teamList = [];
      var data =
        "usrNo=" +
        this.value1 +
        "&infuserStatus=" +
        this.value2 +
        "&current=" +
        this.currentPage +
        "&size=" +
        this.pageSize;

      this.$axios
        .post("/web_userteam/select_myuser_team", data)
        .then(result => {
          if (result.data.status == 0) {
            this.total = result.data.data.total;
            this.page = Math.ceil(result.data.data.total / this.pageSize);
            let data = result.data.data.records;
            this.teamList = data;
            this.teamList.forEach(item => {
              if (item.userId) {
                item.withdrawStatus =
                  item.withdrawStatus == 1 ? "正常" : "冻结";
              }
              if (item.oneTeamConsumeSum == null) {
                item.oneTeamConsumeSum = 0;
              }
              if (item.twoTeamConsumeSum == null) {
                item.twoTeamConsumeSum = 0;
              }
            });
          }
        });
    },
    handleForbidden(withdrawStatus, userId) {
      var status;
      if (withdrawStatus == "1") {
        status = 0;
      } else {
        status = 1;
      }
      let data = "usrId=" + userId + "&auditStatus=" + status;
      this.$confirm("此操作将修改状态, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.$axios.post("/web_userteam/update_status", data).then(result => {
            if (result.data.status == 0) {
              if (result.data.data == true) {
                if (withdrawStatus == "1") {
                  this.get_teamList();
                  return this.$message({
                    type: "success",
                    message: "冻结成功"
                  });
                } else {
                  this.get_teamList();
                  return this.$message({
                    type: "success",
                    message: "启用成功"
                  });
                }
              } else {
                return this.$message({
                  type: "warning",
                  message: "修改失败"
                });
              }
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消修改"
          });
        });
    },

    jump_users_detail1(id) {
      localStorage.setItem(
        "pageMsg",
        JSON.stringify({
          value1: this.value1,
          value2: this.value2,
          currentPage: this.currentPage,
          pageSize: this.pageSize
        })
      );
      //console.log(JSON.parse(localStorage.getItem("pageMsg")), "ooooooo-");
      this.$router.push("/teamDirectTotal?id=" + id);
    },
    jump_users_detail2(id) {
      localStorage.setItem(
        "pageMsg",
        JSON.stringify({
          value1: this.value1,
          value2: this.value2,
          currentPage: this.currentPage,
          pageSize: this.pageSize
        })
      );
      this.$router.push("/teamDirectConsume?id=" + id);
    },
    jump_users_detail3(id) {
      localStorage.setItem(
        "pageMsg",
        JSON.stringify({
          value1: this.value1,
          value2: this.value2,
          currentPage: this.currentPage,
          pageSize: this.pageSize
        })
      );
      this.$router.push("/teamDirectNew?id=" + id);
    },
    jump_users_detail4(id) {
      localStorage.setItem(
        "pageMsg",
        JSON.stringify({
          value1: this.value1,
          value2: this.value2,
          currentPage: this.currentPage,
          pageSize: this.pageSize
        })
      );
      this.$router.push("/teamIndirectTotal?id=" + id);
    },
    jump_users_detail5(id) {
      localStorage.setItem(
        "pageMsg",
        JSON.stringify({
          value1: this.value1,
          value2: this.value2,
          currentPage: this.currentPage,
          pageSize: this.pageSize
        })
      );
      this.$router.push("/teamIndirectConsume?id=" + id);
    },
    jump_users_detail6(id) {
      localStorage.setItem(
        "pageMsg",
        JSON.stringify({
          value1: this.value1,
          value2: this.value2,
          currentPage: this.currentPage,
          pageSize: this.pageSize
        })
      );
      this.$router.push("/teamIndirectNew?id=" + id);
    }
  }
};
</script>


<style lang="less" >
.usersmanage-container {
  @import "../../style/table.less";
  @import "../../style/content.less";
  display: flex;
  flex-flow: column;
  position: relative;
  height: 100%;
  .el-table .cell {
    white-space: pre-line !important;
  }
  #box {
    display: none;
  }
  .el-table__body tr:hover {
    #box {
      display: block;
    }
  }
  .content {
    .query {
      .btn {
        .el-button {
          width: 70px;
        }
      }
    }
  }
}
</style>
